package com.example.fresheveryday.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.example.fresheveryday.po.Log;
import com.example.fresheveryday.po.Productorder;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author ll
 * @since 2023-07-05
 */
@Mapper
public interface ProductorderMapper extends BaseMapper<Productorder> {
    String createOrder(Productorder productorder,int id[]);
    @Select("select * from productorder where orderId = #{ordersId}")
    @Results(id = "ordersMap",value = {
            @Result(column = "orderId",property = "orderid",id = true),
            @Result(column = "orderId",property = "orderdetailets",many = @Many(select = "com.example.fresheveryday.mapper.SuborderMapper.getListByOrdersId"))
    })
    public Productorder getOrdersByOrdersId(String ordersId);

    @Select("select * from productorder where userId = #{userId} order by created desc")
    @ResultMap(value = "ordersMap")
    public List<Productorder> getOrdersList(String userId);

    //动态查询
    @Select("select * from" + " productorder ${ew.customSqlSegment} " )
    @Results({
            @Result(column = "distid",property = "userreceiveinfo",one = @One(select = "com.example.fresheveryday.mapper.UserreceiveinfoMapper.selectById"))
    }
    )
    IPage<Productorder> getOrderByConditions(IPage<Productorder> page, @Param("ew") Wrapper wrapper);
    //
    @Select("select count(orderId) from productorder ${ew.customSqlSegment}")
    int countByConditions(@Param("ew") Wrapper wrapper);
}
